Public Class GDALDriver

    Private obj As Long


    ' ----------------------------------------------------------------------------
    Public Sub New()
        obj = 0
    End Sub

    ' ----------------------------------------------------------------------------
    Public Sub CInit(ByVal obj_in As Long)
        obj = obj_in
    End Sub

    ' ----------------------------------------------------------------------------
    Public Function Create(ByVal Filename As String, _
         ByVal XSize As Long, ByVal YSize As Long, ByVal BandCount As Long, _
         ByVal DataType As Long, ByVal Options As Object) As GDALDataset

        If obj <> 0 Then
            Dim CSLOptions As Long, ds_obj As Long

            CSLOptions = GDALCore.VariantToCSL(Options)
            ds_obj = GDALCore.GDALCreate(obj, Filename, XSize, YSize, BandCount, _
                                         DataType, CSLOptions)
            Call GDALCore.CSLDestroy(CSLOptions)

            If ds_obj <> 0 Then
                Dim ds As New GDALDataset
                Call ds.CInit(ds_obj, 1)
                Create = ds
            End If
        End If
    End Function

    ' ----------------------------------------------------------------------------
    Public Function CreateCopy(ByVal Filename As String, ByVal SrcDS As GDALDataset, _
    ByVal ApproxOK As Boolean, ByVal Options As Object) As GDALDataset

        If obj <> 0 And SrcDS.GetObjPtr() Then
            Dim CSLOptions As Long, ds_obj As Long, ApproxOK_Int As Long

            If ApproxOK Then
                ApproxOK_Int = 1
            Else
                ApproxOK_Int = 0
            End If

            CSLOptions = GDALCore.VariantToCSL(Options)
            ds_obj = GDALCore.GDALCreateCopy(obj, Filename, SrcDS.GetObjPtr(), _
                                             ApproxOK_Int, CSLOptions, 0, 0)
            Call GDALCore.CSLDestroy(CSLOptions)

            If ds_obj <> 0 Then
                Dim ds As New GDALDataset
                Call ds.CInit(ds_obj, 1)
                CreateCopy = ds
            End If
        End If
    End Function

    ' ----------------------------------------------------------------------------
    Public Function GetMetadata(ByVal Domain As String) As Object
        If obj <> 0 Then
            GetMetadata = GDALCore.GetMetadata(obj, Domain)
        End If
    End Function

    ' ----------------------------------------------------------------------------
    Public Function SetMetadata(ByVal MetaData As Object, ByVal Domain As String) As Object
        If obj <> 0 Then
            SetMetadata = GDALCore.SetMetadata(obj, MetaData, Domain)
        Else
            SetMetadata = GDALCore.ObjIsNULLError
        End If
    End Function

    ' ----------------------------------------------------------------------------
    Public Function GetMetadataItem(ByVal Name As String, ByVal Domain As String) As String
        If obj <> 0 Then
            GetMetadataItem = GDALCore.CStr2VB(GDALCore.GDALGetMetadataItem(obj, _
                                               Name, Domain))
        Else
            GetMetadataItem = vbNullString
        End If
    End Function

    ' ----------------------------------------------------------------------------
    Public Function SetMetadataItem(ByVal Name As String, _
    ByVal Value As String, ByVal Domain As String) As Long
        If obj <> 0 Then
            SetMetadataItem = GDALCore.GDALSetMetadataItem(obj, Name, Value, Domain)
        Else
            SetMetadataItem = GDALCore.ObjIsNULLError
        End If
    End Function

    ' ----------------------------------------------------------------------------
    Public Function GetShortName() As String
        If obj <> 0 Then
            GetShortName = GDALCore.CStr2VB(GDALCore.GDALGetDescription(obj))
        End If
    End Function

End Class
